<?php
/**
 * ClassName: RoomService
 * Description: 房间管理Service
 * @Author 周昌
 * @Create 2023/11/8 14:00
 */

namespace service\admin;


use epii\cache\Cache;
use service\BaseService;

class RoomService extends BaseService
{
    public static $room_type=[0=>'男',1=>'女',2=>'混合'];
    public static $room_type_index=['man'=>0,'woman'=>1,'mix'=>2];
    public static $is_vip=[0=>'否',1=>'是'];
    public static $is_vip_index=['no'=>0,'yes'=>1];
    protected static $model='model\RoomModel';
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * #User: Administrator
     * #Time: 2023/11/8 14:08
     * #Author:周昌
     * #Description:
     * @return array
     */
    public static function roomTypeSelect()
    {
        static $room_type_select=[];
        if(empty($room_type_select)){
            foreach (self::$room_type as $k=>$v){
                    $row=[];
                    $row['id']=$k;
                    $row['name']=$v;
                    $room_type_select[]=$row;
            }
            array_unshift($room_type_select,['id'=>'','name'=>'-----请选择-----']);
        }
        return $room_type_select;
    }

    /**
     * #User: Administrator
     * #Time: 2023/11/13 15:31
     * #Author:周昌
     * #Description: 房间vip 下拉选择
     * @return array
     */
    public static function roomVipSelect()
    {
        static $room_vip_select=[];
        if(empty($room_vip_select)){
            foreach (self::$is_vip as $k=>$v){
                $row=[];
                $row['id']=$k;
                $row['name']=$v;
                $room_vip_select[]=$row;
            }
            array_unshift($room_vip_select,['id'=>'','name'=>'-----请选择-----']);
        }
        return $room_vip_select;
    }
    //列表数据
    public static function getAjaxData($where)
    {
        $table = self::$model::order('id desc');
        return self::tableJsonData($table, $where, function ($data){
            $data['type_name'] = self::$room_type[$data['type']];
            $data['vip_name'] = self::$is_vip[$data['is_vip']];
            $data['hospital_name'] = $data['hospital_id']?HospitalService::getNameByKey($data['hospital_id'],''):'';
            return $data;
        });
    }

}